package com.myself.model.demo.netty.foundation;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;
import io.netty.util.CharsetUtil;

import java.util.List;
/**
 * @author Czx
 */
public class NettyEncoder extends MessageToMessageEncoder {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object o, List list) throws Exception {
        System.out.println("开始编码");
        String buffer = (String) o;
        list.add(Unpooled.copiedBuffer(buffer, CharsetUtil.UTF_8));
    }
}
